/**主控制器*/
Ext.define("core.app.controller.MainController",{
	extend : "Ext.app.Controller",
	init : function(){
		var self = this;

		this.addFunItem=function(funInfo){
			if(funInfo){
				var mainView=funInfo.mainView;
				var funPanel=mainView.down(funInfo.funViewXtype);
				if(!funPanel){
					self.application.getController(funInfo.funController).init();
					funPanel=Ext.create(funInfo.funViewName);
					mainView.add(funPanel);
					mainView.setActiveTab(funPanel);
				}else{
					mainView.setActiveTab(funPanel);
				}
			}
		},
		///**下在是控制部分*/
		this.control({
			/**注销*/
			"topview button[ref=logout]" : {
				click: function(btn){
					Ext.Ajax.request({
						waitMsg: '正在注销……',
						url: "user/logout.do",
						method: "POST",
						timeout: 4000,
						success: function (response, opts) {
							var resObj = Ext.decode(response.responseText);
							if (resObj.success) {
								function callBack() {
									location.href = "login.jsp";
								}

								Ext.Msg.alert("提示", resObj.msg, callBack);
							} else {
								Ext.Msg.alert("提示", resObj.msg);
							}
						}
					});
				}
			},
		//
		//	//别名 xtype选择器，对象，响应点击事件
			"westview treepanel":{
				itemclick:function(tree,record,item,index,e,eOpts){
					var mainView=tree.up("mainviewlayout").down("centerview");//向上找父节点，再向下找子节点
					/**用户管理*/
					if(record.data["id"]=="userManager"){
						self.addFunItem({
							mainView:mainView,
							funViewXtype:"userlayout",
							funController:"core.user.controller.UserController",
							funViewName:"core.user.view.UserLayout"
						});
                        /**批量配置*/
                    }else if(record.data["id"]=="batchManager"){
                        self.addFunItem({
                            mainView:mainView,
                            funViewXtype:"productlayout",
                            funController:"core.product.controller.ProductController",
                            funViewName:"core.product.view.ProductLayout"
                        });
                        /*定时计划*/
                    }else if(record.data["id"]=="timePlan"){
                        self.addFunItem({
                            mainView:mainView,
                            funViewXtype:"timePlanLayout",
                            funController:"core.timePlan.controller.TimePlanController",
                            funViewName:"core.timePlan.view.TimePlanLayout"
                        });
					}
				}//itemclick end
			}//"westview treepanel" end
		});
	},
	views : [
		"core.app.view.TopView",
		"core.app.view.WestView",
		"core.app.view.CenterView",
		"core.app.view.MainViewLayout"
	],
	store : [],
	model : []
});